/**
 * @Method form
 * @Description TODO
 * @Date 2021/1/20 9:52
 * @Created by HePing
 */
export default {
  props: {
    model: {
      type: Object,
      default() {
        return {}
      }
    },
    config: {
      type: Object,
      default() {
        return {
          formProps: {},
          rules: {},
          elements: []
        }
      }
    }
  },
  methods: {
    clearValidate() {
      this.$refs.veForm.clearValidate()
    },
    async validate() {
      return this.$refs.veForm.validate()
    }
  },
  render(h) {
    const vm = this
    const { formProps, rules } = vm.config
    let labelWidth = formProps && formProps.labelWidth
    labelWidth = isNaN(labelWidth) ? labelWidth : `${labelWidth}px`
    return h(
      'el-form',
      {
        props: {
          ...formProps,
          rules,
          model: vm.model,
          labelWidth
        },
        ref: 'veForm',
        class: 've-form'
      },
      vm.$slots.default
    )
  }
}
